package com.uenpay.im.ui.old.activity.oa;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aswife.ui.MaskImageView;
import com.uenpay.im.R;

import java.util.ArrayList;

/**
 * @author SL
 * @created 2016-3-24 下午2:25:40
 * @copyRight http://www.qiyunxin.com
 */
public class OaModuleAdapter extends BaseAdapter {

    private LayoutInflater mLayoutInflater = null;
    private ArrayList<AppEntity> arrayList = null;

    public OaModuleAdapter(Context _Context,
                           ArrayList<AppEntity> _ArrayList) {
        arrayList = _ArrayList;
        mLayoutInflater = LayoutInflater.from(_Context);
    }

    @Override
    public int getCount() {
        return arrayList == null ? 0 : arrayList.size();
    }

    @Override
    public Object getItem(int arg0) {
        return arrayList == null ? null : arrayList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        OaModuleViewHodler hodler = null;
        if (arg1 == null) {
            hodler = new OaModuleViewHodler();
            arg1 = mLayoutInflater.inflate(R.layout.item_oa_module_layout,
                    arg2, false);
            hodler.resouceImage = (MaskImageView) arg1
                    .findViewById(R.id.oa_module_type_iv);
            hodler.resouceText = (TextView) arg1
                    .findViewById(R.id.oa_module_type_tv);
            arg1.setTag(hodler);
        } else {
            hodler = (OaModuleViewHodler) arg1.getTag();
        }

        hodler.resouceImage.SetUrl(arrayList.get(arg0).logo);
        hodler.resouceText.setText(arrayList.get(arg0).title);
        return arg1;
    }

    private class OaModuleViewHodler {
        private TextView resouceText;
        private MaskImageView resouceImage;
    }

}
